from functools import reduce


def singleNumber(nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    return reduce(lambda x, y: x ^ y, nums)


print(singleNumber([2, 2, 1]))  # 1
print(singleNumber([4, 1, 2, 1, 2]))  # 4
